package cn.szzsi.service;

import cn.szzsi.common.model.Member;
import com.jfinal.weixin.sdk.api.ApiResult;
import com.jfinal.weixin.sdk.api.UserApi;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhengy on 2017/1/7.
 */
public class WeiXinBusinessService {
    /**
     * 通过扫码推荐获取用户信息
     */
    public static Member processCommendUserInfo(String sceneid, String pids, String shopId, String apiid, String openid, String registerIp, String code) {
        Map<String, Object> map = new HashMap<String, Object>();
        try {
            ApiResult apiResult = UserApi.getUserInfo(openid);
            String nickname = apiResult.getStr("nickname");
            String sex = apiResult.getInt("sex").toString();
            String city = apiResult.getStr("city");
            String province = apiResult.getStr("province");
            String country = apiResult.getStr("country");
            String headimgurl = apiResult.getStr("headimgurl");
            map.put("openid", openid);
            map.put("nickname", nickname);
            map.put("sex", sex);
            map.put("city", city);
            map.put("province", province);
            map.put("country", country);
            map.put("headimgurl", headimgurl);
            Member m = Member.saveMemberInfo(sceneid,pids,openid,nickname,sex,country,province,city,headimgurl,null,null,shopId,registerIp, code);
            //循环发送关注模板消息
            return m;
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        return null;
    }
}
